# utils.c File Reference

Utility functions. More...

Go to the source code of this file.

## Functions

int | str2ffmt (char *str)
uint8_t | set_bit_in_byte (uint8_t src, int bit, int val)
uint16_t | set_bit_in_word (uint16_t src, int bit, int val)
uint64_t | get_program_time (void)
DList * | dlist_add (DList *head, AvrClass *data, DListFP_Cmp cmp)
DList * | dlist_add_head (DList *head, AvrClass *data)
DList * | dlist_delete (DList *head, AvrClass *data, DListFP_Cmp cmp)
void | dlist_delete_all (DList *head)
AvrClass * | dlist_lookup (DList *head, AvrClass *data, DListFP_Cmp cmp)
AvrClass * | dlist_get_head_data (DList *head)
DList * | dlist_iterator (DList *head, DListFP_Iter func, void *user_data)

## Detailed Description

Utility functions.

This module provides general purpose utilities.

Definition in file utils.c.

## Function Documentation

int str2ffmt | ( | char * | str | ) |

Utility function to convert a string to a FileFormatType code.

Definition at line 50 of file utils.c.

uint8_t set_bit_in_byte | ( | uint8_t | src,
|  | int | bit,
|  | int | val |
| ) |  |  |

Set a bit in src to 1 if val != 0, clears bit if val == 0.

uint16_t set_bit_in_word | ( | uint16_t | src,
|  | int | bit,
|  | int | val |
| ) |  |  |

Set a bit in src to 1 if val != 0, clears bit if val == 0.

uint64_t get_program_time | ( | void |  | ) |

Return the number of milliseconds of elapsed program time.

Returns:
  an unsigned 64 bit number. Time zero is not well defined, so only time differences should be used.

Definition at line 76 of file utils.c.

References avr_error.

Referenced by avr_core_run().

DList* dlist_add | ( | DList * | head,
|  | AvrClass * | data,
|  | DListFP_Cmp | cmp |
| ) |  |  |

Add a new node to the end of the list.

If cmp argument is not NULL, use cmp() to see if node already exists and don't add node if it exists.

It is the responsibility of this function to unref data if not added.

Definition at line 159 of file utils.c.

References class_unref().

DList* dlist_add_head | ( | DList * | head,
|  | AvrClass * | data |
| ) |  |  |

Add a new node at the head of the list.

Definition at line 196 of file utils.c.

DList* dlist_delete | ( | DList * | head,
|  | AvrClass * | data,
|  | DListFP_Cmp | cmp |
| ) |  |  |

Conditionally delete a node from the list.

Delete a node from the list if the node's data matches the specified data. Returns the head of the modified list.

Definition at line 215 of file utils.c.

References avr_error, and class_unref().

Referenced by dlist_iterator().

void dlist_delete_all | ( | DList * | head | ) |

Blow away the entire list.

Definition at line 266 of file utils.c.

References class_unref().

Referenced by avr_core_destroy().

AvrClass* dlist_lookup | ( | DList * | head,
|  | AvrClass * | data,
|  | DListFP_Cmp | cmp |
| ) |  |  |

Lookup an item in the list.

Walk the list pointed to by head and return a pointer to the data if found. If not found, return NULL.

Parameters:

  | head | The head of the list to be iterated.
  | data | The data to be passed to the func when it is applied.
  | cmp | A function to be used for comparing the items.

Returns:
  A pointer to the data found, or NULL if not found.

Definition at line 291 of file utils.c.

References avr_error.

Referenced by mem_get_vdevice_by_name().

AvrClass* dlist_get_head_data | ( | DList * | head | ) |

Extract the data from the head of the list.

Returns the data element for the head of the list. If the list is empty, return a NULL pointer.

Parameters:

  | head | The head of the list.

Returns:
  A pointer to the data found, or NULL if not found.

Definition at line 321 of file utils.c.

DList* dlist_iterator | ( | DList * | head,
|  | DListFP_Iter | func,
|  | void * | user_data |
| ) |  |  |

Iterate over all elements of the list.

For each element, call the user supplied iterator function and pass it the node data and the user_data. If the iterator function return non-zero, remove the node from the list.

Parameters:

  | head | The head of the list to be iterated.
  | func | The function to be applied.
  | user_data | The data to be passed to the func when it is applied.

Returns:
  A pointer to the head of the possibly modified list.

Definition at line 357 of file utils.c.

References avr_error, and dlist_delete().

Automatically generated by Doxygen 1.5.5 on 7 Nov 2008.